<div class="doc-item" id="doc-916"><h2 class="doc-item-name">import-static<span class="namespace">(clojure.contrib.import-static)</span></h2><p class="macro">Macro</p><ul class="var-arglists"><li>(<span class="var-name">import-static</span> class &amp; fields-and-methods)</li></ul><div class="var-docstring"><p>Imports the named static fields and/or static methods of the class
  as (private) symbols in the current namespace.</p><p>Example: 
      user=&gt; (import-static java.lang.Math PI sqrt)
      nil
      user=&gt; PI
      3.141592653589793
      user=&gt; (sqrt 16)
      4.0</p><p>Note: The class name must be fully qualified, even if it has already
  been imported.  Static methods are defined as MACROS, not
  first-class fns.</p></div><div class="var-source"><pre>; clojure/contrib/import_static.clj:22
(defmacro import-static
  [class &amp; fields-and-methods]
  (let [only (set (map str fields-and-methods))
        the-class (. Class forName (str class))
        static? (fn [x]
                    (. java.lang.reflect.Modifier
                       (isStatic (. x (getModifiers)))))
        statics (fn [array]
                    (set (map (memfn getName)
                              (filter static? array))))
        all-fields (statics (. the-class (getFields)))
        all-methods (statics (. the-class (getMethods)))
        fields-to-do (intersection all-fields only)
        methods-to-do (intersection all-methods only)
        make-sym (fn [string]
                     (with-meta (symbol string) {:private true}))
        import-field (fn [name]
                         (list 'def (make-sym name)
                               (list '. class (symbol name))))
        import-method (fn [name]
                          (list 'defmacro (make-sym name)
                                '[&amp; args]
                                (list 'list ''. (list 'quote class)
                                      (list 'apply 'list
                                            (list 'quote (symbol name))
                                            'args))))]
    `(do ~@(map import-field fields-to-do)
         ~@(map import-method methods-to-do))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>